// /////////////////////////////////////////////////////////////////////////////
//
// Name:            GameState.cpp
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           The GameState object is a base class which is implemented
//                  through derived sub-classes.
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

// Include files
#include "GameState.h"
#include "../scripting/ScriptHelper.h"


// GameState class
// Static variables.
u32 GameState::mIDCount = 0;

// Constructer of the GameState class.
GameState::GameState()
{
    mID = mIDCount++;

    // Create the base entity.
    std::stringstream ss;
    ss << "GameState#" << mID;
    mBaseEntity = GameManager::Instance()->getEntityManager()->createEntity(ss.str());
}

// Deconstructor of the GameState class.
GameState::~GameState()
{
    GameManager::Instance()->getEntityManager()->removeEntity(mBaseEntity);
}

// Initialises the GameState.
// -> Implemented by subclass.
void GameState::init()
{
}

// Clears the GameState.
// -> Implemented by subclass.
void GameState::clear()
{
}

// Updates the GameState.
// -> Implemented by subclass.
void GameState::update(f32 deltaTime)
{
}

// Renders the GameState.
// -> Implemented by subclass.
void GameState::render()
{
}

// Returns the base entity.
Entity* GameState::getBaseEntity() const
{
    return mBaseEntity;
}

// Gets the ID of this state.
u32 GameState::getID() const
{
    return mID;
}

// Event functions
// Sends the "onUpdate" event to all entities subscribed to this state.
void GameState::onUpdate(f32 deltaTime)
{
    mBaseEntity->emitEvent("onUpdate", &deltaTime);
}

// Sends the "onUpdate" event to all entities subscribed to this state.
void GameState::onRender()
{
    mBaseEntity->emitEvent("onRender");
}

// Sends the "onPause" event to all entities subscribed to this state.
void GameState::onPause()
{
    mBaseEntity->emitEvent("onPause");
}

// Sends the "onUnPause" event to all entities subscribed to this state.
void GameState::onUnPause()
{
    mBaseEntity->emitEvent("onUnPause");
}

// End of File
